package one.stand.zuul.config;

import lombok.extern.slf4j.Slf4j;
import one.stand.common.cache.PvCacheModel;
import one.stand.util.RedisUtil;
import one.stand.zuul.filter.AccessFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PvTask {
    @Autowired
    private RedisUtil redisUtil;

    @Scheduled(cron = "0 */5 * * * ?")
    public void updatePv() {
        long pv = AccessFilter.longAdder.sumThenReset();
        log.info("update pv:{}", pv);
        PvCacheModel pvCacheModel = new PvCacheModel(redisUtil);
        pvCacheModel.save(Math.toIntExact(pv));
    }
}
